﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using AspNetCs.Model;
using System.Data;
using AspNetCs.Common;
using System.Collections;
namespace AspNetCs.SQLServerDAL
{
    public class Cemetery_AddNumId_DAL : ICemetery_AddNumId
    {

        #region ICemetery_AddNumId 成员
        db.ParameterArry[] par = new db.ParameterArry[9];





        public Cemetery_AddNumId_DAL()
        {
        }

        /// <summary>
        /// 参数
        /// </summary>
        /// <param name="md"></param>
        /// <returns></returns>
        public db.ParameterArry[] param(Cemetery_AddNumId_Model md)
        {

            db.ParameterArry[] par = new db.ParameterArry[10];

            par[0].dbType = SqlDbType.Int;
            par[0].objValue = md.Id;
            par[0].parName = "@id";

            par[1].dbType = SqlDbType.VarChar;
            par[1].objValue = md.NumId;
            par[1].parName = "@Numid";

            par[2].dbType = SqlDbType.VarChar;
            par[2].objValue = md.CemeteryNames;
            par[2].parName = "@CemeteryNames";

            par[3].dbType = SqlDbType.Int;
            par[3].objValue = md.CemeteryId;
            par[3].parName = "@CemeteryId";

            par[4].dbType = SqlDbType.Int;
            par[4].objValue = md.TempleId;
            par[4].parName = "@TempleId";

            par[5].dbType = SqlDbType.Int;
            par[5].objValue = md.PositionX;
            par[5].parName = "@positionX";


            par[6].dbType = SqlDbType.Int;
            par[6].objValue = md.PositionY;
            par[6].parName = "@positionY";

            par[7].dbType = SqlDbType.VarChar;
            par[7].objValue = md.Addtime;
            par[7].parName = "@Addtime";

            par[8].dbType = SqlDbType.VarChar;
            par[8].objValue = md.NetIP;
            par[8].parName = "@NetIP";

            par[9].dbType = SqlDbType.Int;
            par[9].objValue = md.UserId;
            par[9].parName = "@UserId";




            return par;
        }







        public Cemetery_AddNumId_Model GetModel(DataRow dr)
        {
            Cemetery_AddNumId_Model md = new Cemetery_AddNumId_Model();
            try
            {
                if (dr != null)
                {
                    if (dr["id"] != null) { md.Id = StringHelper.isNumber_int(dr["id"].ToString()); }
                    if (dr["Numid"] != null) { md.NumId = dr["Numid"].ToString(); }
                    if (dr["CemeteryNames"] != null) { md.CemeteryNames = dr["CemeteryNames"].ToString(); }
                    if (dr["CemeteryId"] != null) { md.CemeteryId = StringHelper.isNumber_int(dr["CemeteryId"].ToString()); }
                    if (dr["TempleId"] != null) { md.TempleId = StringHelper.isNumber_int(dr["TempleId"].ToString()); }
                    if (dr["positionX"] != null) { md.PositionX = StringHelper.isNumber_int(dr["positionX"].ToString()); }
                    if (dr["positionY"] != null) { md.PositionY = StringHelper.isNumber_int(dr["positionY"].ToString()); }
                    if (dr["Addtime"] != null) { md.Addtime = dr["Addtime"].ToString(); }
                    if (dr["NetIP"] != null) { md.NetIP = dr["NetIP"].ToString(); }
                    if (dr["UserId"] != null) { md.UserId = StringHelper.isNumber_int(dr["UserId"].ToString()); }
                }
            }
            catch
            {
                md = null;
            }

            return md;
        }

        public int Add(Cemetery_AddNumId_Model md)
        {
            int Result = 0;
            db.ParameterArry[] parAdd = param(md);
            try
            {
                db ConnInsert = new db();
                Result = ConnInsert.ExcSql("Insert into Cemetery_AddNumId(Numid,CemeteryNames,CemeteryId,TempleId,positionX,positionY,NetIP,UserId) values(@Numid,@CemeteryNames,@CemeteryId,@TempleId,@positionX,@positionY,@NetIP,@UserId)", parAdd);
                ConnInsert.close();
            }
            catch
            {
                Result = -1;
            }
            return Result;
        }

        public int Delete(string filter)
        {

            throw new NotImplementedException();


        }

        public List<Cemetery_AddNumId_Model> GetData(string filter)
        {
            List<Cemetery_AddNumId_Model> list = new List<Cemetery_AddNumId_Model>();
            DataTable dt = GetDataTable(filter);
            foreach (DataRow dr in dt.Rows)
            {
                list.Add(GetModel(dr));
            }
            return list;
        }

        public DataTable GetDataTable(string filter)
        {
            string Wherestr = "";

            if (filter != "")
            {
                Wherestr += "  where " + filter;

            }
            db ConnInfo = new db();
            DataTable dt = null;
            try
            {
                dt = ConnInfo.GetSql_DataTable("Select * from Cemetery_AddNumId" + Wherestr);
            }
            catch
            {

            }
            ConnInfo.close();
            return dt;
        }

        public int Update(string Upfilter, string filter)
        {
            int result = 0;
            try
            {
                if (filter != "")
                {
                    filter = " where " + filter;
                }
                db ConnUpdate = new db();
                result = ConnUpdate.ExcSql("update Cemetery_AddNumId Set " + Upfilter + "  " + filter);
            }
            catch
            {
                result = -1;
            }
            return result;
        }

        public int delete(string filter)
        {
            int result = 0;
            try
            {
                db Cn = new db();
                if (filter != "")
                {
                    filter = " where " + filter;
                }
                result = Cn.ExcSql("delete From Cemetery_AddNumId " + filter);
                Cn.close();
            }
            catch
            {
                result = -1;
            }
            return result;
        }

        #endregion
    }
}
